#include<iostream>
#include<sys/ipc.h>
#include<sys/shm.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
using namespace std;

#define SIZE 4096
#define pathname "/home/zwt"
#define proj_id 100
#define FIFOFILE "./myfifo"
#define MODE 0664

key_t GetKey(){
    key_t key=ftok(pathname,proj_id);
    if(key==-1){
        perror("ftok error\n");
        return -1;
    }
    return key;
}

int CreateShmHelp(int flag){
    key_t key=GetKey();
    int n=shmget(key,SIZE,flag);
    if(n==-1){
        perror("shmget error\n");
        return -1;
    }
    return n;
}
int CreateShm(){
    return CreateShmHelp(IPC_CREAT|IPC_EXCL|0664);
}
int GetShm(){
    return CreateShmHelp(IPC_CREAT);
}